package jtk.project4.fleet.screen.maintenanceDueDetails;

import java.awt.FlowLayout;

import jtk.project4.fleet.field.*;
import nl.coderight.jazz.form.FormField;
import nl.coderight.jazz.form.FormLayout;
import nl.coderight.jazz.form.FormView;
import nl.coderight.jazz.form.FormLayout.Resize;
import nl.coderight.jazz.form.control.GroupControl;
import nl.coderight.jazz.form.control.TabControl;
import nl.coderight.jazz.form.control.TabItem;
import nl.coderight.jazz.form.field.button.PushButton;

public class MaintenanceDueDetailsView extends FormView{
	private TabControl maintenanceDueTab;
	private TabItem preventiveMaintenanceDueTab;
	private TabItem repairMaintenanceDueTab;

	private PushButton generateWOButton;
	private PushButton printButton;
	private PushButton helpButton;
	private PushButton closeButton;
	
	@Override
	protected void init() {
		// TODO Auto-generated method stub
		createTabFields();		
		createFields();
		createLayout();
	}
	
	private void createLayout() {
		addField(createForm());
	}
	
	private void createFields() {
		generateWOButton = new PushButton("Generate WO");
		printButton = new PushButton("Print");
		helpButton = new PushButton("Help");
		closeButton = new PushButton("Close");
	}
	
	private void createTabFields()
	{
		maintenanceDueTab = new TabControl();
		preventiveMaintenanceDueTab = new TabItem("Preventive Maintenance Due");
		repairMaintenanceDueTab = new TabItem("Repair Maintenance Due");
	}
	
	private FormField createTabs()
	{
		TabControl form = maintenanceDueTab;
		form.addTab(preventiveMaintenanceDueTab, createMaintenanceDueTab());
		form.addTab(repairMaintenanceDueTab, repairMaintenanceDueTab());
		return form;
	}
	
	private GroupControl createMaintenanceDueTab() {
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())
		.addField(new PreventiveMaintenanceDueTableField("Preventive Maintenance Due"))
		;				
		
		return form;
	}
	
	private GroupControl repairMaintenanceDueTab() {
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())
		.addField(new EquipmentRepairMaintenanceDueField("Repair Maintenance Due"))
		;				
		
		return form;
	}
	
	private GroupControl maintenanceHighlightingField() {
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())
		.addField(new MaintenanceHighlightingField("Maintenance Highlighting"))
		;				
		
		return form;
	}
	
	private GroupControl currentInformationField() {
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())
		.addField(new CurrentInformationField("Current Information"))
		;				
		
		return form;
	}
	
	private FormField createForm()
	{
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())
		.addField(createTabs(),CENTER,Resize.HORIZONTAL)
		.addRow()
		.addField(createButtons())
		.addRow()
		.addField(maintenanceHighlightingField()) 
		.addField(currentInformationField())
		;
		
		return form;
	}
	
	/*private GroupControl createGeneralForm() {
		GroupControl form = new GroupControl();
		form.addField(createGeneralForm(), NORTH);
		form.addField(createButtons(), SOUTH);
		return form;
	}*/
	
	private GroupControl createButtons() {
		GroupControl buttons = new GroupControl();
		buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
		buttons.addField(generateWOButton);
		buttons.addField(printButton);
		buttons.addField(helpButton);
		buttons.addField(closeButton);
		return buttons;
	}
}